﻿


Public Class HighResolutionTimer

    Private _start As Long
    Private _stop As Long
    Private _frequency As Long

    Public Sub New()
        QueryPerformanceFrequency(_frequency)
    End Sub

    Public Sub Start()
        QueryPerformanceCounter(_start)
    End Sub

    Public Sub [Stop]()
        QueryPerformanceCounter(_stop)
    End Sub

    Public ReadOnly Property ElapsedTime() As Single
        Get
            Dim elapsed As Single = ((CSng(_stop - _start)) / (CSng(_frequency)))
            Return elapsed
        End Get
    End Property

    <System.Runtime.InteropServices.DllImport("KERNEL32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto)> _
    Private Shared Function QueryPerformanceCounter(ByRef performanceCount As Long) As Boolean
    End Function

    <System.Runtime.InteropServices.DllImport("KERNEL32.dll", charset:=Runtime.InteropServices.CharSet.Auto)> _
    Private Shared Function QueryPerformanceFrequency(ByRef frequency As Long) As Boolean
    End Function

End Class
